﻿package frEngine.shader
{
    import __AS3__.vec.*;
    import flash.display3D.*;
    import flash.events.*;
    import frEngine.*;
    import frEngine.event.*;
    import frEngine.manager.*;

    public class FrProgram3D extends Object
    {
        public var program:Program3D;
        public var VcParamsConstList:Vector.<VcParam>;
        public var FcParamsConstList:Vector.<FcParam>;
        public var paramsMaxtrixList:Vector.<MaxtrixParam>;
        public var textures:Vector.<FsParam>;
        public var VaParamsList:Vector.<VaParam>;
        public var uvRepeat:Boolean;
        private var _programeId:String;
        private var _instanceRegister:Program3dRegisterInstance;

        public function FrProgram3D(param1:Boolean, param2:String, param3:Program3dRegisterInstance)
        {
            this.uvRepeat = param1;
            this._programeId = param2;
            this.instanceRegister = param3;
            return;
        }// end function

        public function get programeId() : String
        {
            return this._programeId;
        }// end function

        public function get instanceRegister() : Program3dRegisterInstance
        {
            return this._instanceRegister;
        }// end function

        public function set instanceRegister(param1:Program3dRegisterInstance) : void
        {
            this._instanceRegister = param1;
            if (!param1)
            {
                return;
            }
            this.program = this._instanceRegister.program;
            this.VcParamsConstList = this._instanceRegister.VcParamsConstList;
            this.FcParamsConstList = this._instanceRegister.FcParamsConstList;
            this.paramsMaxtrixList = this._instanceRegister.paramsMaxtrixList;
            this.textures = this._instanceRegister.textures;
            this.VaParamsList = this._instanceRegister.VaParamsList;
            FrEventDispatcher.instance.proxyAddEventListener(this._instanceRegister, Engine3dEventName.CONTEXT_REUPLOAD, this.resetProgramHander);
            return;
        }// end function

        private function resetProgramHander(event:Event) : void
        {
            this.program = this._instanceRegister.program;
            return;
        }// end function

        public function dispose() : void
        {
            this.VcParamsConstList = null;
            this.FcParamsConstList = null;
            this.paramsMaxtrixList = null;
            this.textures = null;
            this.VaParamsList = null;
            FrEventDispatcher.instance.proxyRemoveEventListener(this._instanceRegister, Engine3dEventName.CONTEXT_REUPLOAD, this.resetProgramHander);
            Program3dManager.instance.pushPrograme3DtoPool(this._instanceRegister, this.uvRepeat);
            this._instanceRegister = null;
            return;
        }// end function

        public function getParamByName(param1:String, param2:Boolean)
        {
            if (!this._instanceRegister)
            {
                return null;
            }
            return this._instanceRegister.getParamByName(param1, param2);
        }// end function

    }
}
